import wepy from 'wepy';
import env from './config'

const host = env.host;

/*
	params: {
		method: 'GET' || 'POST',
		data: {}
	}
*/
const wxRequest = async (params = {}, url) => {
    wepy.showToast({
      title: '加载中',
      icon: 'loading'
    });

    let res = await wepy.request({
        url: url,
        method: params.method || 'GET',
        data: params.data || {},
        header: {'Content-Type': 'application/json'},
    });
    wepy.hideToast();

    return res;
};

// Index
const register = (params) => wxRequest(params, host + '/wxRegister/')
const login = (params) => wxRequest(params, host + '/userLogin/')
const view = (params) => wxRequest(params, host + '/getMct/' + params.query.id)
const breTicket = (params) => wxRequest(params, host + '/getBriefTickets/' + params.query.id)
const getTicket = (params) => wxRequest(params, host + '/getTicket/' + params.query.id)
const getPrice = (params) => wxRequest(params, host + '/getActivePrice/')
const creatOrder = (params) => wxRequest(params, host + '/createOrder/')
const showOrder = (params) => wxRequest(params, host + '/showOrders/' + params.query.id + '?status=' + params.query.status)
const getOrder = (params) => wxRequest(params, host + '/getOrder/' + params.query.id)
const getPay = (params) => wxRequest(params, host + '/miniPay/')
const ticketDetail = (params) => wxRequest(params, host + '/tickets/' + params.query.id)

module.exports = {
	register,
    login,
    view,
    breTicket,
    getTicket,
    getPrice,
    creatOrder,
    showOrder,
    getOrder,
    getPay,
    ticketDetail
}
